home *** CD-ROM | disk | FTP | other *** search
- Path: hubcap.clemson.edu!mjs
- From: mjs@hubcap.clemson.edu (M. J. Saltzman)
- Newsgroups: comp.lang.pl1,comp.lang.c
- Subject: Re: PL/I and C
- Date: 29 Feb 1996 17:21:36 GMT
- Organization: Clemson University, The Great State of South Carolina
- Message-ID: <4h4nb0$cnj@hubcap.clemson.edu>
- References: <4gn5d8$t5f@newsbf02.news.aol.com> <4gril3$sn9@goanna.cs.rmit.EDU.AU> <31320777.2810@corp.dialog.com>
- NNTP-Posting-Host: hubcap.clemson.edu
-
- In article <31320777.2810@corp.dialog.com> Paul Gorodyansky <paul_gorodyansky@corp.dialog.com> writes:
- >As I said, I just found out that my posting went also to
- > comp.lang.C group, in addition to PL/I group.
- >
- >[Incitement to commit langauge war...]
- >
- > All you, C guys who replied, paid TOO MUCH attention to my note
- >about UNIONS, but it's a MINOR thing compared to other AWFUL for
- >an *application* programmer things in C that I listed.
- >In systems/low-level tasks C may be Perfect.
-
- We were focused on unions becasue that was the first article in the
- thread to appear in comp.lang.c.
-
- >[C is bad because of...]
- >Just 2 examples of our NORMAL, REGULAR code (nothing special).
- >
- >I. Select/Switch statement.
- >-----------------------
- > This important part of ANY *application* program is VERY
- > -------
- > rudimental and hard to use in C - you can use ONLY numbers here:
- >
- >switch(my_choice) {
- > case 0:
- >....
- > break;
- > case 1:
- >....
- > break;
- >}
- >
- >You can use Enumerations in C but they are still only NUMBERS.
- > -------
-
- Yes, C's switch construct is less well-designed then it might be (I'd
- like to see ranges on case labels, for example), but the following
- doesn't seem very compelling to me.
-
- > In PL/I you can use any Expression (!) as a switch, that makes a
- > code close to specs and easy to read and modify:
- > -------------- ------------ ------
- >
- >Select(Source_Tag);
- > When( 'AN' )
- > .....
- > When ( 'PD', 'PY', 'SO' )
- > ...
- > When
- > ...
- > When
- > ...
- >End;
-
- I'll concede that the comparable C is somewhat more tedious in this case.
-
-
- if ( strcmp(Source_Tag, "AN") == 0 ) {
- ...
- } else if ( strcmp(Source_Tag, "PD") == 0 ||
- strcmp(Source_Tag, "PY") == 0 ||
- strcmp(Source_Tag, "SO") == 0 } {
- } else if ( ... ) {
-
- }
-
- One could use a lookup function to good advantage here. But this
- particular example is as much about the fact that strings are not
- first-class types as it is about the limitations of the switch
- statement.
-
- > or something like that
- >
- >Select;
- > When ( SUBSTR(INREC,4,1) = ' ' )
- > ....
- > When
- > ...
- > When ( INDEX(UPALPHA,Cur_Tag) > 0 &
- > VERIFY(W_TAG23,'0123456789') = 0 )
- > ....
- > When ( String_1 || String_2 = String_3 )
- > ...
- >End;
- >
- >It is how SPECIFICATIONS look like, so for a person who works
- >with this program FIRST time, it is CLEAR, after reading specs,
- >what this part of code is doing.
- > Just TRY to implement it in C !!!
- >You will HAVE TO find some 'work around', so it will be further
- > ------
- >from specs and the piece of the code will be much BIGGER and LESS
- >clear, harder to understand.
-
- The C idiom for this construct is:
-
- if ( SUBSTR(INREC,4,1) = ' ' ) {
- ....
- } else if ( ... ) {
- ...
- } else if ( INDEX(UPALPHA,Cur_Tag) > 0 &&
- VERIFY(W_TAG23,'0123456789') = 0 ) {
- ...
- } else if ( strcmp(strcat(String_1, String_2), String_3) == 0 ) {
- ...
- }
-
- It doesn't seem so tough to understand, or even so different. What are
- PL/I semantics when more than one of the When conditions is true?
-
- (Of course, String_1 was modified by the C code, but not by the PL/I
- code, but that's just a consequence of the way strings are treated
- by the standard library functions, not part of the "When versus
- switch" argument.)
-
- >Just another example. Strings.
-
- Others have pointed out that string libraries can be built to
- handle most of these objections. Yes, it's true that strings
- are not a first-class type in C.
-
- C is not perfect, but then again, neither is PL/I. You can write
- unreadable, unmaintainable code in either, with no trouble at all.
- With a certain amount of care (perhaps marginally more in one language
- than the other in some casees), you can write readable, maintainable
- code in either as well. Both languages have their "gotchas".
-
- Beware, though, when critiquing langauge design, of the difference
- between things that are really bad and things that you're just not
- used to.
- --
- Matthew Saltzman
- Clemson University Math Sciences
- mjs@clemson.edu
-